#! /bin/sh

### BEGIN INIT INFO
# Provides:          mongodb
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the mongodb database server
# Description:       starts mongodb using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/node-home-automation/src/app.js
NAME=node-home-automatino

test -r $DAEMON || exit 0

case "$1" in
  start)
	echo -n "Starting $NAME: "
	screen -d -m npm start
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $NAME: "
	sudo killall screen
    sudo killall node-dev
    sudo killall node
	echo "$NAME."
	;;
#  restart)
#	echo -n "Restarting $NAME: "
#	start-stop-daemon --stop --quiet --pidfile \
#		$PID --exec $DAEMON || true
#	sleep 1
#	start-stop-daemon --start --quiet --pidfile \
#		$PID --exec $DAEMON -- $DAEMON_OPTS || true
#	echo "$NAME."
#	;;
  status)
	status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
	;;
  *)
	echo "Usage: $NAME {start|stop|restart|status}" >&2
	exit 1
	;;
esac

exit 0